package src;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.InputStream;

public class SuperMan {
    int i=1;
    int j=1;
    int k=1;
    boolean toright=true;
    public SuperMan(int manx, int many, String imagePath) {
        this.manx = manx;
        this.many = many;
        this.ImagePath = imagePath;
    }
    public SuperMan(){
    }

    private int manx=200;
    private int many=200;
    private String ImagePath="image/toright1.png";
    private String pose="static";

    public String getPose() {
        return pose;
    }

    public void setPose(String pose) {
        this.pose = pose;
    }

    public int getManx() {
        return manx;
    }

    public void setManx(int manx) {
        this.manx = manx;
    }

    public int getMany() {
        return many;
    }

    public void setMany(int many) {
        this.many = many;
    }

    public String getImagePath() {
        return ImagePath;
    }

    public void setImagePath(String imagePath) {
        ImagePath = imagePath;
    }
    public BufferedImage StreamToImage(String str){
        InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream(str);
        BufferedImage bufferedImage=null;
        try {
            bufferedImage= ImageIO.read(resourceAsStream);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bufferedImage;

    }

    public void drawMe(Graphics g){




         if(pose.equals("right")) {

            ImagePath = "image/toright" + i + ".png";
             System.out.println(i);
            BufferedImage bufferedImage = StreamToImage(ImagePath);
            i++;

            manx += 10;

            Image image = new ImageIcon(bufferedImage).getImage();
            g.drawImage(image, manx, many, null);
            if (i > 3) {
                toright=true;

                i = 1;
                this.pose="static";
            }

        }
        else if(pose.equals("left")) {


            ImagePath = "image/toleft" + i + ".png";
            BufferedImage bufferedImage = StreamToImage(ImagePath);
            i++;
            manx -= 10;

            Image image = new ImageIcon(bufferedImage).getImage();
            g.drawImage(image, manx, many, null);
            if (i > 3) {
                toright=false;
                i = 1;
                this.pose="static";
            }

        }
        else if(pose.equals("foot"))
         {
             if(toright)
             {
                 ImagePath = "man/foot" + j + ".png";
                 BufferedImage bufferedImage = StreamToImage(ImagePath);
                 j++;
                 manx += 3;

                 Image image = new ImageIcon(bufferedImage).getImage();
                 g.drawImage(image, manx, many, null);
                 if (j > 6) {
                     j = 1;
                     this.pose = "static";
                 }

             }
             else{
                 ImagePath = "man/foot" + j + "-modified.png";
                 BufferedImage bufferedImage = StreamToImage(ImagePath);
                 j++;
                 manx -= 3;

                 Image image = new ImageIcon(bufferedImage).getImage();
                 g.drawImage(image, manx, many, null);
                 if (j > 6) {
                     j = 1;
                     this.pose = "static";
                 }

             }


         }
        else if(pose.equals("hand"))
         {
             if(toright)
             {
                 ImagePath = "man/hand" + k + ".png";
                 BufferedImage bufferedImage = StreamToImage(ImagePath);
                 k++;
                 manx += 1;

                 Image image = new ImageIcon(bufferedImage).getImage();
                 g.drawImage(image, manx, many, null);
                 if (k > 5) {
                     k = 1;
                     this.pose = "static";
                 }

             }
             else{
                 ImagePath = "man/hand" + k+ "-modified.png";
                 BufferedImage bufferedImage = StreamToImage(ImagePath);
                 k++;
                 manx -= 1;

                 Image image = new ImageIcon(bufferedImage).getImage();
                 g.drawImage(image, manx, many, null);
                 if (k > 5) {
                     k= 1;
                     this.pose = "static";
                 }

             }

         }
         else if(pose.equals("defense")) {

             if(toright){
                 ImagePath = "man/defence.png";
                 BufferedImage bufferedImage = StreamToImage(ImagePath);
                 Image image = new ImageIcon(bufferedImage).getImage();
                 g.drawImage(image, manx, many, null);

             }
             else
             {
                 ImagePath = "man/defence-modified.png";
                 BufferedImage bufferedImage = StreamToImage(ImagePath);
                 Image image = new ImageIcon(bufferedImage).getImage();
                 g.drawImage(image, manx, many, null);

             }




         }
        else{
            if(toright)
            {
                ImagePath = "image/toright" + 1 + ".png";
                BufferedImage bufferedImage = StreamToImage(ImagePath);
                Image image = new ImageIcon(bufferedImage).getImage();
                g.drawImage(image, manx, many, null);

            }
            else
            {
                ImagePath = "image/toleft" + 1 + ".png";
                BufferedImage bufferedImage = StreamToImage(ImagePath);
                Image image = new ImageIcon(bufferedImage).getImage();
                g.drawImage(image, manx, many, null);
            }


        }








    }


}
